/**
 * @author gabriele.cerfoglio@usi.ch
 */

package ch.usi.inf.pf2;

import java.io.FileNotFoundException;
import java.io.ObjectInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;

public class FileLoader {
	public static Object load(String filename, String type) {
		// Creating a generic object variable, and the input for file and
		// object.
		ArrayList partList = new ArrayList();
		WaveForm wave = null;
		FileInputStream fileInp = null;
		ObjectInputStream objectInp = null;

		try {
			fileInp = new FileInputStream(filename);
			objectInp = new ObjectInputStream(fileInp);

			if (type.equals("WaveForm")) {
				wave = (WaveForm) objectInp.readObject();
				objectInp.close();
				return wave;
			}

			else if (type.equals("LogicSimMain")) {
				partList = (ArrayList) objectInp.readObject();
				objectInp.close();
				return partList;
			}

		} catch (FileNotFoundException e) {
			System.out.println("there is no such file or directory");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;

		// Reading from the file and writing into the object.
	}
}
